<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars
define("PRIMARY_KEY","kdcust");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_custlist_2.php";
if (GetParam("Template","")=="DN") $FileTemplate = "ais_transaction_custlist_listdn.html";
elseif ((GetParam("FormName","")=="MemorialTransForm") && !GetParam("SendToBack","")) $FileTemplate = "ais_transaction_custlist_memotrans.html";
elseif ((GetParam("FormName","")=="CashBankForm" ) && !GetParam("SendToBack","")) {$FileTemplate = "ais_transaction_custlist_cashbanktrans.html";}
elseif ((GetParam("FormName","")=="CashBankPaymentForm") && !GetParam("SendToBack","")) {$FileTemplate = "ais_transaction_custlist_cashbanktrans_pay.html";}
elseif ((GetParam("FormName","")=="CNSummaryForm") && !GetParam("SendToBack","")) {$FileTemplate = "ais_transaction_custlist_dnlist.html";}
else $FileTemplate  = "ais_transaction_custlist_nr.html";

$PageSize      = 10 ;
$TableName     = "tblprojectassignment";
$HTMLGridList  = "ProjectAssignmentGrid";

//************ FORM ACTION **************
    if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
    }

$PreserveGet = GetQueryString("All", array("PageNum"));
//Initiate Database Table For Search;
$FNama = GetParam("debturSearch","");
$FCode = GetParam("debturCodeSearch","");
$transDate = GetParam("transDate","");

$show_data = GetParam("show_data","");



//Check if there is on grid or not
$temp_no_urut = GetParam("no_urut","");

if(!empty($temp_no_urut))
{
  $no_urut = GetParam("no_urut","");
}
else
{
   $no_urut = "";
}
//

//Check if Show All Data



$FormName = GetParam("FormName","");
$testrama = GetParam("ProjectId","");
//******* DATABASE FORM QUERY ***********

/*
$SQL = "SELECT * FROM $TableName a
        JOIN tblproject b ON a.project_id = b.project_id
        JOIN tbldebtur c ON a.debtur = c.CUDEBTUR
        where a.project_id=$testrama";
*/

if($show_data == "all")
{    
    $SQL = "SELECT *, CUCODE as debtur, CUNAME as debnam FROM tbldebtur ";

	if ($FNama)
		if (strlen($WHERE)) $WHERE .= " AND "." cuname like '%".$FNama."%'";
		else $WHERE .= " cuname like '%".$FNama."%'";
	if ($FCode)
		if (strlen($WHERE)) $WHERE .= " AND "." cudebtur like '%".$FCode."%'";
		else $WHERE .= " cudebtur like '%".$FCode."%'";

		if (strlen($WHERE)) $WHERE = " WHERE ".$WHERE;
		else $WHERE = " WHERE 1 ";

	$SQL = $SQL.$WHERE;
	
	
	
	$WHERE = "";
	
	$SQLCount = "SELECT count(*) FROM tbldebtur ";

	if ($FNama)
		if (strlen($WHERE)) $WHERE .= " AND "." cuname like '%".$FNama."%'";
		else $WHERE .= " cuname like '%".$FNama."%'";
	if ($FCode)
		if (strlen($WHERE)) $WHERE .= " AND "." cudebtur like '%".$FCode."%'";
		else $WHERE .= " cudebtur like '%".$FCode."%'";

		if (strlen($WHERE)) $WHERE = " WHERE ".$WHERE;
		else $WHERE = " WHERE 1 ";

	$SQLCount = $SQLCount.$WHERE;
	
	
}



else
{
    
	$SQL = "SELECT * FROM $TableName a
			JOIN tblproject b ON a.project_id = b.project_id
			JOIN tbldebtur c ON a.debtur = c.CUDEBTUR ";

	if ($FNama)
		if (strlen($WHERE)) $WHERE .= " AND "." c.cuname like '%".$FNama."%'";
		else $WHERE .= " c.cuname like '%".$FNama."%'";
	if ($FCode)
		if (strlen($WHERE)) $WHERE .= " AND "." c.cudebtur like '%".$FCode."%'";
		else $WHERE .= " c.cudebtur like '%".$FCode."%'";

		if (strlen($WHERE)) $WHERE = " WHERE a.project_id='".$testrama."' AND ".$WHERE;
		else $WHERE = " WHERE a.project_id='".$testrama."' ";

	$SQL = $SQL.$WHERE;
	
	
	
	$WHERE = "";
	
	$SQLCount = "SELECT count(*) FROM $TableName a
			JOIN tblproject b ON a.project_id = b.project_id
			JOIN tbldebtur c ON a.debtur = c.CUDEBTUR ";

	if ($FNama)
		if (strlen($WHERE)) $WHERE .= " AND "." cuname like '%".$FNama."%'";
		else $WHERE .= " cuname like '%".$FNama."%'";
	if ($FCode)
		if (strlen($WHERE)) $WHERE .= " AND "." cudebtur like '%".$FCode."%'";
		else $WHERE .= " cudebtur like '%".$FCode."%'";

		if (strlen($WHERE)) $WHERE = " WHERE a.project_id='".$testrama."' AND ".$WHERE;
		else $WHERE = " WHERE a.project_id='".$testrama."' ";

	
    $SQLCount = $SQLCount.$WHERE;

	
}




//******* SHOW FORM CONTENT *********

//$PageNum = 1;
//$RecCnt = $DBConnection->dbc->get_var($SQLCount) ;
//if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");
//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
}

//echo "$SQL"; exit;

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();



?>
